package org.jks.service;

import java.io.Serializable;
import java.util.List;

import org.hibernate.Session;
import org.jks.model.MsgTask;
import org.jks.util.MessageUtil;
import org.springframework.stereotype.Service;

@Service
public class MsgTaskService extends EntityService<MsgTask>{
	
	public MsgTaskService(){
		MODEL_NAME = MsgTask.class.getSimpleName();
		CLASS_NAME = MsgTask.class;
	}
	
	@Override
	public Serializable save(List<MsgTask> list) {
		Session session = this.openSession();
		Serializable obj = null;
		
		try{
			session.getTransaction().begin();
			for(MsgTask o : list){
				obj = session.save(o);
			}
			session.getTransaction().commit();
			MessageUtil.add(list);
		}
		catch(Exception e){
			session.getTransaction().rollback();
		}
		session.flush();
		session.close();
		
		return obj;
	}

	@Override
	public Serializable save(MsgTask o) {
		Session session = this.openSession();
		Serializable obj = null;
		try{
			obj = session.save(o);
			MessageUtil.add(o);
		}
		catch(Exception e){
			
		}
		session.flush();
		session.close();
		return obj;
	}

}
